<?

session_start();


function get_likes() {

    if (isset( $_SESSION['userid'])) {

        $uid = $_SESSION['userid'];

    } else {

        $sess = @$_COOKIE['PHPSESSID'];
    
        if (empty($sess)) {
            die();
        }
  
        $q = "SELECT session, dealid, like FROM like WHERE session='%s'";
        $q = sprintf($q, $sess);
        $r = MYSQL_Q($q);
    }
}


function like_deal($deal, $like) {

    if (isset( $_SESSION['userid'])) {

        $uid = $_SESSION['userid'];
    
    } else {
    
        $sess = @$_COOKIE['PHPSESSID'];
    
        if (empty($sess)) {
            die();
        }
    
        $q = "SELECT * FROM like WHERE session = '%s' AND dealid = '%s'";
    }
}


$op = @$_GET['op'];

if (empty($op)) {
    die();
}

if ($op == 'get') {

    get_likes();

} else if ($op == 'set') {

    $like = $_GET['like'];
    $deal = $_GET['deal'];

    if (empty($like)) {
        die();
    }

    if (empty($deal)) {
        die();
    }

    like_deal($deal, $like);
}

 
?>